#include "line.h"
#include <algorithm>
#include <cmath>

Line::Line()
{
}

Line::Line(const Point &p0, const Point &p1)
{
    vertex[0] = p0;
    vertex[1] = p1;
}

double Line::distance(const Point &pt, bool bSeg)
{
    Vector v0 = vertex[1] - vertex[0];
    Vector v1 = pt - vertex[0];
    Vector v2 = pt - vertex[1];
    double dis;

    if (bSeg && (v0.dot(v1) < 0 || v0.dot(v2) > 0))
    {
        dis = std::min(pt.distance(vertex[0]), pt.distance(vertex[1]));
    }
    else
    {
        v0.normalize();
        v2 = v1.cross(v0);
        dis = fabs(v2.z());
    }

    return dis;
}

void Line::draw()
{
}
